#!/bin/sh

# $Id: icecast2,v 1.5 2009-03-20 09:10:36 brian Exp $
# Copyright (c)2007 Brian Manning <brian at portaboom dot com>

# PLEASE DO NOT E-MAIL THE AUTHOR ABOUT THIS SOFTWARE
# The proper venue for questions is the LACK mailing list at:
# http://groups.google.com/linuxack or <linuxack.googlegroups.com>

if ! [ -e $LACK_FUNCTIONS ]; then
    LACK_FUNCTIONS="/etc/scripts/lack_functions.sh"
fi # if ! [ -e $LACK_FUNCTIONS ]
source $LACK_FUNCTIONS

ACTION=$1
BINARY=/usr/bin/icecast2
[ -x "$BINARY" ] || exit 1
BASENAME=$(/usr/bin/basename $BINARY)
DESC="icecast2 HTTP Streaming server"
# -b == background, -c config file
BINARY_OPTS="-b -c /etc/icecast2/icecast.xml"

case "$ACTION" in
    vars)
        # echo out what commandline variables are parsed by this script
        echo "${BASENAME}:"
        exit 0
    ;;
    start)
        IFS_UP=$(/bin/ip address | /bin/grep UP | /usr/bin/wc -l)
        if [ $IFS_UP -gt 0 ]; then
            colorize $S_TIP "Starting $DESC"
            su -s /bin/sh -c "$BINARY $BINARY_OPTS" icecast2 >>$DEBUG_LOG 2&>1
            check_exit_status $? $BASENAME
            # don't know why something here is writing this file...
            rm -f /1
        else
            colorize $S_INFO "Not starting $DESC; no network interfaces up"
        fi
        ;;
    stop)
        colorize $S_TIP "Stopping $DESC"
        kill -TERM $(cat /var/run/icecast.pid)
        check_exit_status $? $BASENAME
        ;;
    restart|force-reload)
         $0 stop
         $0 start
        ;;
    *)
        echo "Usage: $BASENAME {start|stop|restart|force-reload}" >&2
        exit 3
        ;;
esac

exit 0
# vi: set shiftwidth=4 tabstop=4 filetype=sh :
# конец!
